// 
// SoapTrace.Net - A soap message monitoring utility. 
// 
// Copyright (C) 2004 Matthew Ward
// 
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
// 
// Matthew Ward (mrward@users.sourceforge.net)
// 

using System;
using System.Diagnostics;

namespace SoapTrace.Core.Communication
{
	/// <summary>
	/// Represents a soap request and soap response pair.
	/// </summary>
	public class SoapRequestAndResponse
	{
		/// <summary>
		/// The soap request message.
		/// </summary>
		private SoapRequest m_Request;
		
		/// <summary>
		/// The corresponding soap response message.
		/// </summary>
		private SoapResponse m_Response;
		
		/// <summary>
		/// The id of the client that was responsible for
		/// these messages.
		/// </summary>
		private ClientId m_ClientId;

		/// <summary>
		/// Creates new instance of the 
		/// <see cref="SoapRequestAndResponse"/> class.
		/// </summary>
		/// <param name="id">The ID of the client that 
		/// this request/response pair belongs to.</param>
		public SoapRequestAndResponse( ClientId id )
			: this( id, null )
		{
		}

		/// <summary>
		/// Creates new instance of the 
		/// <see cref="SoapRequestAndResponse"/> class.
		/// </summary>
		/// <param name="id">The ID of the client that 
		/// this request/response pair belongs to.</param>
		/// <param name="request">The soap request message.</param>
		public SoapRequestAndResponse( ClientId id, SoapRequest request )
		{
			m_ClientId = id;
			m_Request = request;
		}

		/// <summary>
		/// Gets the soap request.
		/// </summary>
		public SoapRequest Request
		{
			[ DebuggerStepThrough ]
			get
			{
				return m_Request;
			}
		}

		/// <summary>
		/// Gets or sets the soap response.
		/// </summary>
		public SoapResponse Response
		{
			[ DebuggerStepThrough ]
			get
			{
				return m_Response;
			}

			[ DebuggerStepThrough ]
			set
			{
				m_Response = value;
			}
		}

		/// <summary>
		/// Gets the client ID.
		/// </summary>
		public ClientId ClientId
		{
			[ DebuggerStepThrough ]
			get
			{
				return m_ClientId;
			}
		}		

		/// <summary>
		/// Gets the time this request/response pair was received.
		/// </summary>
		public DateTime TimeReceived
		{
			[ DebuggerStepThrough ]
			get
			{
				DateTime TimeReceived = new DateTime( 2000, 1, 1 );
				
				if( m_Request != null )
				{
					TimeReceived = m_Request.TimeReceived;
				}
				else if( m_Response != null )
				{
					TimeReceived = m_Response.TimeReceived;
				}
				
				return TimeReceived;
			}
		}
		
		/// <summary>
		/// Gets the source of this soap request/response message.
		/// </summary>
		public string Source
		{
			get
			{
				string Source = String.Empty;
				
				if( m_Request != null )
				{
					Source = m_Request.Source;
				}
				else if( m_Response != null )
				{
					Source = m_Response.Source;
				}
				
				return Source;
			}
		}

		/// <summary>
		/// Gets the name of the web service.
		/// </summary>
		public string WebService
		{
			[ DebuggerStepThrough ]
			get
			{
				string WebService = String.Empty;
				
				if( m_Request != null )
				{
					WebService = m_Request.WebService;
				}
				
				return WebService;
			}
		}

		/// <summary>
		/// Gets the request uri.
		/// </summary>
		public string Uri
		{
			[ DebuggerStepThrough ]
			get
			{
				string Uri = String.Empty;
				
				if( m_Request != null )
				{
					Uri = m_Request.Uri;
				}
				
				return Uri;
			}
		}

		/// <summary>
		/// Gets the web service operation.
		/// </summary>
		public string WebMethod
		{
			[ DebuggerStepThrough ]
			get
			{
				string WebMethod = String.Empty;
				
				if( m_Request != null )
				{
					WebMethod = m_Request.WebMethod;
				}
				
				return WebMethod;
			}
		}
	}
}
